#include <cmath>
#include <iostream>
using namespace std;

const int kMaxM = 20;
int ans = (int)1e9;
int min_s[kMaxM] = {0}, min_v[kMaxM] = {0};

void Pre(int m) {
  for (int i = 1; i <= m; i++) {
    min_s[i] = min_s[i - 1] + 2 * i * i;
    min_v[i] = min_v[i - 1] + i * i * i;
  }
}

bool VInRange(int max_r, int max_h, int m, int rest_v) {
  int max_v = 0;

  for (int i = 1; i <= m; i++) {
    max_v += (max_r - i) * (max_r - i) * (max_h - i);
  }

  return min_v[m] <= rest_v && rest_v <= max_v;
}

void DFS(int dep, int last_r, int last_h, int s, int rest_v) {
  if (dep == 0) {
    ans = s;
    return;
  }
  for (int r = last_r - 1; r >= dep; r--) {
    for (int h = min(last_h - 1, rest_v / (r * r)); h >= dep; h--) {
      if (s + 2 * r * h + min_s[dep - 1] < ans && VInRange(r, h, dep - 1, rest_v - r * r * h)) {
        DFS(dep - 1, r, h, s + 2 * r * h, rest_v - r * r * h);
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  int n, m;

  cin >> n >> m;
  Pre(m);
  for (int r = (int)sqrt(n / m); r >= m; r--) {
    for (int h = n / (r * r); h >= m; h--) {
      int v = r * r * h;
      int s = r * r + 2 * r * h;
      if (s + min_s[m - 1] < ans && VInRange(r, h, m - 1, n - v)) {
        DFS(m - 1, r, h, s, n - v);
      }
    }
  }
  if (ans == (int)1e9) {
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}